﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="update.aspx.cs" MasterPageFile="~/master/Main.Master" Inherits="HungryCrowd.category.update" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server" ClientIDMode="Static">
    <div class="formLayout">
        <asp:Label ID="lblHeader" runat="server" ClientIDMode="Static"></asp:Label>
        <div class="col1">Name:</div><div><asp:TextBox ID="txtName" runat="server" ClientIDMode="Static" /></div>
        <div class="col1">Synopsis:</div><div><asp:TextBox ID="txtSynopsis" runat="server" ClientIDMode="Static" /></div>
        <div class="col1">Image:</div><div><asp:FileUpload ID="fluImage" runat="server" ClientIDMode="Static" /></div>
        <div style="width:100%;float:left;margin-left:auto;margin-right:auto;"><asp:Button ID="btnSubmit" Text="Submit" runat="server" Width="80px" ClientIDMode="Static" OnClick="btnSubmit_Click" /><input type="button" id="save" onclick="saveCategory();" value="Save" /></div>
    </div>
    <asp:HiddenField ID="hdfHiddenField" runat="server" ClientIDMode="Static" />
    <script type="text/javascript">
        function saveCategory() {
            debugger;
            //var bytes = $('#fluImage')[0].files[0];
            //var name = $('#txtName').val();
            //var synopsis = $('#txtSynopsis').val();

            //var jsonObj = { 'Name': name, 'Synopsis': synopsis, 'Image': bytes };
            var obj = $('#hdfHiddenField').val();
            var jsonObj = JSON.parse(obj);
            var dataToSend = { Category: JSON.stringify(jsonObj), MethodName: 'SaveCategory' };

            var options = {
                data: dataToSend,
                dataType: 'JSON',
                type: 'POST',
                url:'/server/ajax.aspx',
                success: function (response, status, XHR) {
                    if (status != 'success') {
                        debugger;
                        alert('Error occurred.' + XHR);
                    }
                    else {
                        debugger;

                        if (response == true)
                        alert('success');                        
                    }
                }
            };
            $.ajax(options);
        }
        $('#fluImage').change(function () {
            debugger;
            console.log($(this).val());
        });
    </script>
    
</asp:Content>

